/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Server;
import java.net.*;
import java.io.*;

class ClientConnection extends Thread {

   private Socket client = null;
   private ObjectOutputStream oos = null;
   private ObjectInputStream ois = null;
   private String inLine = null;
   private String outLine = "What's up";
   public ClientConnection() {}
   public ClientConnection(Socket clientSocket) throws IOException {
        client = clientSocket;
        client.setSoTimeout(10000);
        try {
            oos = new ObjectOutputStream(client.getOutputStream());
        } catch(Exception ex) {
            try {
                client.close();
            }catch (Exception e) {
                System.out.println(e.getMessage());
            }
            return;
        }
        try {
            ois = new ObjectInputStream(client.getInputStream());
        } catch(Exception ex) {
            try {
                client.close();
            }catch (Exception e) {
                System.out.println(e.getMessage());
            }
            return;
        }
        this.start();
    }
    public void run() {
     /*   try {
            oos.writeObject(outLine);
            oos.flush();
            oos.close();
            client.close();
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }
      * */
       try {
           oos.writeObject("Good to go");
           while ((inLine = (String) ois.readObject()) != null){
               //inLine = (String) ois.readObject();
               oos.writeObject(inLine + " AND SEND THIS BACK");
               oos.flush();
               System.out.println(inLine);
           }
       }catch(Exception e) {
           System.out.println(e.getMessage());
       }
       try {
           oos.close();
           ois.close();
           client.close();
       }catch(Exception e) {
           System.out.println(e.getMessage());
       }
    }
}
